package com.woniuxy.usercoachassemble.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.woniuxy.usercoachassemble.dao.UserMapper;
import com.woniuxy.usercoachassemble.entity.Attention;
import com.woniuxy.usercoachassemble.dao.AttentionMapper;
import com.woniuxy.usercoachassemble.entity.User;
import com.woniuxy.usercoachassemble.service.AttentionService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author Lucas
 * @since 2020-07-10
 */
@Service
public class AttentionServiceImpl extends ServiceImpl<AttentionMapper, Attention> implements AttentionService {
    @Autowired
    private AttentionMapper attentionMapper;
    @Autowired
    private UserMapper userMapper;



 @Override
    public List<User> selectattentionbyuserid(int userId){

        QueryWrapper<Attention> wrapper=new QueryWrapper();
        wrapper.eq("oneself_id",userId);
       List<Attention> attentions=attentionMapper.selectList(wrapper);
       List<User> lis=new ArrayList<User>();
     System.out.println(attentions);
       for (Attention attention:attentions){
           System.out.println(attention.getOthersId());
           System.out.println(userMapper.selectById(2));
           lis.add(userMapper.selectById(attention.getOthersId()));
       }
        return lis;
    }
    //取消关注
    @Override
    public  void   cancellattenton(int oneself_id, int others_id){
        QueryWrapper<Attention> wrapper=new QueryWrapper();
        wrapper.eq("oneself_id",oneself_id);
        wrapper.eq("others_id",others_id);
        attentionMapper.delete(wrapper);
    }

    //添加关注
    @Override
    public void addattention(Attention attention){
        attentionMapper.insert(attention);

    }

    @Override
    public List<Map<String, Object>> selectFriend(int userId) {
        List<Map<String, Object>>  maps= attentionMapper.selectFriend(userId);
        return maps;
    }
    /**
     * @description:TODO(单字段查询用户)
     * @param field 用户名/昵称/电话
     * @param roleId 角色
     * @return:  org.example.Result
     * @author: Fy浪迹、
     * @date: 2020/7/21 23:47
     */
    @Override
    public List<Map<String, Object>> singleFieldSelectUser(String field, Integer roleId) {

        Map<String, Object> map = new HashMap<>();
        map.put("field",field);
        map.put("roleId",roleId);
        List<Map<String, Object>> users = attentionMapper.singleFieldSelectUser(map);
        return users;
    }
}
